package com.quanyan.ic.parkingLot.http.service.impl;

import com.quanyan.ic.parkingLot.http.dao.TestMapper;
import com.quanyan.ic.parkingLot.http.entity.TbTest;
import com.quanyan.ic.parkingLot.http.service.TestService;
import com.quanyan.ic.parkingLot.utils.HikTokenGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Created by zhang on 17/8/18.
 */
@Service
public class TestServiceImpl implements TestService {
    private final static Logger logger = LoggerFactory.getLogger(TestServiceImpl.class);
    @Autowired
    private TestMapper testMapper;
    @Value("${hik.parking.appkey}")
    private String hikParkingAppkey;
    @Value("${hik.parking.secret}")
    private String hikParkingSecret;
    @Value("${hik.parking.address}")
    private String hikParkingAddress;



    @Override
    public TbTest queryTestById(Integer id) {

        String path = "/api/parking/test/queryTestById";
        String param = "?a=1&b=k&c=110";

        String result = HikTokenGenerator.generatorGetToken(hikParkingAddress, path, param, hikParkingAppkey, hikParkingSecret);
        logger.info("get result:" + result);

        return testMapper.queryTestById(id);
    }

    @Override
    public TbTest insertTest(TbTest test) {
        int n = testMapper.insertTest(test);
        TbTest result = null;
        if (n > 0) {
            result = testMapper.queryTestById(test.getId());
        }
        return result;
    }
}
